package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.Pagingable;
import com.yxy.base.RestResponse;
import com.yxy.dto.TableProductOrderInfoDto;
import com.yxy.service.TableProductOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author huangxinrong
 * 商品订单管理
 */
@RestController
@Slf4j
  @RequestMapping("/tableProductOrderInfo")//必须要加
public class TableProductOrderInfoController {

  @Autowired
  private TableProductOrderInfoService tableProductOrderInfoService;

  // 获取商品订单列表
  @Pagingable//添加分页
  @PostMapping("/list")
  public RestResponse getList(@RequestBody TableProductOrderInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableProductOrderInfoService.getlist(pojo));
    return restResponse;
  }


  // 获取商品订单列表
  @PostMapping("/appGetOrderList")
  public RestResponse appGetOrderList(@RequestBody TableProductOrderInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableProductOrderInfoService.appGetOrderList(pojo));
    return restResponse;
  }

  // 获取商品订单列表
  @PostMapping("/getInventoryAndSalesDayListUp")
  public RestResponse getInventoryAndSalesDayListUp(@RequestBody TableProductOrderInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableProductOrderInfoService.getInventoryAndSalesDayListUp(pojo));
    return restResponse;
  }

  // 获取商品订单列表
  @PostMapping("/listCount")
  public RestResponse getListCount(@RequestBody TableProductOrderInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableProductOrderInfoService.getlist(pojo));
    return restResponse;
  }

  // 获取商品订单列表
  @Pagingable//添加分页
  @PostMapping("/appStoreList")
  public RestResponse getAppStoreList(@RequestBody TableProductOrderInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableProductOrderInfoService.getlist(pojo));
    return restResponse;
  }

  //修改商品订单类型信息
  @PostMapping("/update")
  public RestResponse update(@RequestBody @Valid  TableProductOrderInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableProductOrderInfoService.modify(pojo));
    return restResponse;
  }

  //新增商品订单类型信息
  @PostMapping("/create")
  public RestResponse create(@RequestBody @Valid  TableProductOrderInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableProductOrderInfoService.save(pojo));
    return restResponse;
  }



  //新增商品订单类型信息
  @PostMapping("/appCreateOrder")
  public RestResponse appCreateOrder(@RequestBody @Valid TableProductOrderInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    List<TableProductOrderInfoDto> tableProductOrderInfoDtoList = pojo.getTableProductOrderInfoDtoList();
    restResponse.setContent(tableProductOrderInfoService.appCreateOrder(tableProductOrderInfoDtoList));
    return restResponse;
  }


  //根据id删除商品订单类型信息
  @PostMapping("/delete")
  public RestResponse delete(@RequestBody @Valid  TableProductOrderInfoDto pojo) throws BusinessException {
    RestResponse restResponse = new RestResponse(200, "成功");
    restResponse.setContent(tableProductOrderInfoService.delete(pojo.getId().toString()));
    return restResponse;
  }
}
